package com.ruoyi.ysg.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.ysg.domain.YsgCourse;
import com.ruoyi.ysg.domain.YsgSetMeal;
import com.ruoyi.ysg.service.IYsgSetMealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/ysg/setMeal")
public class YsgSetMealController extends BaseController {

    @Autowired
    private IYsgSetMealService setMealService;
    /**
     * 查询套餐管理列表
     */
    @PreAuthorize("@ss.hasPermi('ysg:setMeal:list')")
    @GetMapping("/list")
    public TableDataInfo list(YsgSetMeal ysgSetMeal)
    {
        startPage();
        List<YsgSetMeal> list = setMealService.selectSetMealList(ysgSetMeal);
        return getDataTable(list);
    }

    /**
     * 获取套餐详细信息
     */
    @PreAuthorize("@ss.hasPermi('ysg:setMeal:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(setMealService.selectYsgSetMealById(id));
    }

    /**
     * 新增套餐管理
     */
    @PreAuthorize("@ss.hasPermi('ysg:setMeal:add')")
    @Log(title = "套餐管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YsgSetMeal ysgSetMeal)
    {
        return toAjax(setMealService.insertYsgSetMeal(ysgSetMeal));
    }

    /**
     * 修改套餐管理
     */
    @PreAuthorize("@ss.hasPermi('ysg:setMeal:edit')")
    @Log(title = "套餐管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YsgSetMeal ysgSetMeal)
    {
        return toAjax(setMealService.updateYsgSetMeal(ysgSetMeal));
    }

    /**
     * 删除套餐管理
     */
    @PreAuthorize("@ss.hasPermi('ysg:setMeal:remove')")
    @Log(title = "套餐管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(setMealService.deleteYsgSetMealByIds(ids));
    }


    /**
     * 导出套餐列表
     */
    @PreAuthorize("@ss.hasPermi('ysg:setMeal:export')")
    @Log(title = "套餐管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YsgSetMeal ysgSetMeal)
    {
        List<YsgSetMeal> list = setMealService.selectSetMealList(ysgSetMeal);
        ExcelUtil<YsgSetMeal> util = new ExcelUtil<YsgSetMeal>(YsgSetMeal.class);
        util.exportExcel(response, list, "套餐数据");
    }

}
